<template>
	<view class="main">
		<guide v-if="guidePages" :advData="advData" :time="advData.time"></guide>
	</view>
</template>

<script>
	import guide from '@/components/guide/index.vue'
	import Cache from '@/utils/cache';
	import {
		getOpenAdv
	} from '@/api/api.js'
	import {
		mapGetters
	} from 'vuex';
	export default {
		components: {
			guide
		},
		computed: {
			...mapGetters(['routeError']),
		},
		data() {
			return {
				guidePages: false,
				advData: []
			}
		},
		onShow() {
			this.loadExecution()
		},
		methods: {
			loadExecution() {
				const tagDate = uni.getStorageSync('guideDate') || 0,
					nowDate = new Date().getTime();
				if ((tagDate+10*60*1000) > nowDate) {
					this.pageJump(1);
					return
				}
				getOpenAdv().then(res => {
					if (res.data.status == 0 || res.data.value.length == 0) {
						this.pageJump(1);
					} else if (res.data.status && (res.data.value.length || res.data.video_link)) {
						this.advData = res.data
						
						let route_state = res.data.mp_switch || '0';
						this.$store.commit('ROUTE_ERROR',route_state);
						let recordStartTime = new Date().getTime();
						uni.setStorageSync('guideDate', recordStartTime);
						
						this.guidePages = true
					}
				}).catch(err => {
					this.pageJump(0);
				})
			},
			/**
			 * 已知状态传1  意料之外传0
			 */
			pageJump(status){
				let jumpTo = 0;
				if(status == 1 && !this.routeError) {
					jumpTo = 1;
				}
				// if(jumpTo == 0){
				// 	uni.reLaunch({
				// 		url: '/pages/index/index'
				// 	});
				// }else {
					uni.switchTab({
						url:'/pages/shops/index/index'
					})
				// }
			},
			
		},
		onHide() {
			this.guidePages = false
		}
	}
</script>

<style>
	page,
	.main {
		width: 100%;
		height: 100%;
	}
</style>
